import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/net/response/patrol/patrol_record_list_data.dart';
import 'package:ls_work/ui/patrol/patrol_detail_page.dart';
import 'package:ls_work/util/ext_utils.dart';
import 'package:ls_work/viewmodel/patrol/patrol_record_detail_view_model.dart';

class PatrolRecordDetailPage extends BaseStatefulMvvmWidget{

  final PatrolRecordListData item;

  PatrolRecordDetailPage({required this.item });

  @override
  State<StatefulWidget> createState() => _PatrolRecordState();

}

class _PatrolRecordState extends BaseMvvmListState<PatrolRecordDetailViewModel,PatrolRecordDetailPage>{
  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      backgroundColor: Color(0xfff1f1f1),
      appBar: AppBar(title: Text(widget.item.name??""),),
      body: loadingContentWidget,
    );
  }

  @override
  Widget createItemWidget(int index) {
    var item = viewModel.listItems[index];
    return Stack(
      alignment: Alignment.center,
      children: [
        Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              children: [
                CommonText(item.pointName).setWeight(1),
                CommonText(item.resultStatusName,
                    textColor: item.resultStatus == 1 ? Colors.blue : item
                        .resultStatus == 2 ? Colors.green:Colors.red
                )
              ],
            ),

            Container(height: 8,),
            CommonText('打卡时间：${item.executeDate??""}'),
            Container(height: 8,),
            CommonText('反馈：${item.feedback??''}')
          ],
        ),
        if(item.resultStatus==0&&widget.item?.timeOutStatus==true)
          TextButton(onPressed: (){
            showApplyDialog(context: context, onSubmit: (){
              viewModel.addSubmit(item.id);
            },message: "确定提交补卡吗?");
          }, child: CommonText('打卡',textColor: Colors.white),
          style: ButtonStyle(
            backgroundColor: WidgetStateProperty.all(Colors.blue)
          ),).setLocation(right: 0),

        if(item.resultStatus==2)
          TextButton(onPressed: (){
            // showApplyDialog(context: context, onSubmit: (){
            //   viewModel.addSubmit(item.id);
            // },message: "确定提交吗?");
            item.patrolName = widget.item.name;
            item.patrolRange = widget.item.patrolRange;
            item.startTime = widget.item.startDate;
            item.endTime = widget.item.endDate;
            Go().push(PatrolDetailPage("",item:item));
          }, child: CommonText('异常登记',textColor: Colors.white),
            style: ButtonStyle(
                backgroundColor: WidgetStateProperty.all(Colors.red)
            ),).setLocation(right: 0),
      ],
    ).addToContainer(
        width: double.infinity,
        padding: EdgeInsets.all(10),
        decoration:
        BoxDecoration(color: Colors.white, borderRadius: 10.borderRadius));
  }

  @override
  PatrolRecordDetailViewModel createViewModel() {
    return PatrolRecordDetailViewModel(context,item: widget.item);
  }

  @override
  EdgeInsets get listPadding =>
      EdgeInsets.symmetric(horizontal: 16, vertical: 16);

  @override
  Widget get separatorDivider =>
      Container(
        height: 10,
      );

  @override
  bool get canPullUp => true;



}